package com.tanglongan.designPattern.dp16_mediator.demo99;

import lombok.Setter;

public class GenericClient {

    /**
     * 抽象同事类
     */
    static abstract class Colleague {
        protected Mediator mediator;

        public Colleague(Mediator mediator) {
            this.mediator = mediator;
        }
    }

    static class ConcreteColleagueA extends Colleague {
        public ConcreteColleagueA(Mediator mediator) {
            super(mediator);
            this.mediator.setColleagueA(this);
        }

        public void selfMethodA() {
            System.out.println(this.getClass().getSimpleName() + ".self-method");
        }

        public void depMethodA() {
            System.out.println(this.getClass().getSimpleName() + ":depMethod:delegate to Mediator");
            this.mediator.transferA();
        }
    }

    static class ConcreteColleagueB extends Colleague {
        public ConcreteColleagueB(Mediator mediator) {
            super(mediator);
            this.mediator.setColleagueB(this);
        }

        public void selfMethodB() {
            System.out.println(this.getClass().getSimpleName() + ".self-method");
        }

        public void depMethodB() {
            System.out.println(this.getClass().getSimpleName() + ":depMethod:delegate to Mediator");
            this.mediator.transferB();
        }
    }

    @Setter
    static abstract class Mediator {
        protected ConcreteColleagueA colleagueA;
        protected ConcreteColleagueB colleagueB;

        //中介者业务逻辑
        protected void transferA() {
            this.colleagueA.selfMethodA();
        }

        protected void transferB() {
            this.colleagueB.selfMethodB();
        }
    }

    static class ConcreteMediator extends Mediator {
        @Override
        protected void transferA() {
            this.colleagueA.selfMethodA();
        }

        @Override
        protected void transferB() {
            this.colleagueB.selfMethodB();
        }
    }
}
